package framework.account;

import java.util.Date;
import java.util.HashMap;

import framework.interfaces.IAccount;
import framework.interfaces.IAccountManager;

public class AccountManager implements IAccountManager {

	private HashMap<String, IAccount> accountList;

	public AccountManager() {
		accountList = new HashMap<String, IAccount>();
	}

	public void withdraw(String accNo, double amount) {
		accountList.get(accNo).withdraw(amount);
	}

	public void createAccount(IAccount account) {
		accountList.put(account.getAccountType().getAccNo(), account);
	}

	@Override
	public void deposit(String accNo, double amount) {
		accountList.get(accNo).deposit(amount);
	}

	@Override
	public void addInterest(double percent) {
		for (IAccount acc : accountList.values()) {
			acc.addInterest(percent);
		}
	}

	@Override
	public String generateReport(Date begin, Date end) {
		String str = "";
		for (IAccount acc : accountList.values()) {
			str += acc.printStatement(begin, end);
		}
		return str;
	}

	@Override
	public void charge(String accNo, double amount) {
		accountList.get(accNo).deposit(amount);
	}

	public HashMap<String, IAccount> getAccountList() {
		return accountList;
	}
}
